Frameworks: Node is the bedrock upon which many frameworks exist These frameworks built by others are often massive open source projects that then get used by many others. Examples include:
Browserscript: Interacts with the DOM/Cookies/Window
Nodescript: Node works as a server, granting usage to the file system, locally installed packages, environmental control (you can't control what browser the callers are using, but you can control what environment your server's running on).
Module Standards:
Due to the fragmentation of who wrote what when, you'll often see two separate ways of importing modules:
1// ES Module import:
2import moduleObject from 'someModule'
xxxxxxxxxx
21// CommonJS Module Import
2const moduleObject = require("someModule")
When exporting data, you can export a default function, or multiple functions to be treated as an object:
someFile.js
xxxxxxxxxx
11export default () => "This is a value returned from a function!"
someImportingFile.js
x1import whateverNameIWant from './someFile.js'
2// const whateverNameIWant = require('./someFile.js')
3
4console.log(whateverNameIWant())
someOtherFile.js
xxxxxxxxxx
71export const someFunction = () => {
2 return "values"
3}
4
5export const someOtherFunc = () => {
6 return 23
7}
Can be imported as:
xxxxxxxxxx
51import * as something from './someOtherFile.js'
2// const something = require('someOtherFile.js')
3
4const someValue = something.someFunction()
5const someOtherValue = something.someOtherFunc()
OR
xxxxxxxxxx
51import { someFunction, someOtherFunc } from './someOtherFile.js'
2// const { someFunction, someOtherFunc } = require('./someOtherFile.js')
3
4const someValue = someFunction()
5const someOtherValue = someOtherFunc()
Functions can also be exported as:
defaultExportObject.js
xxxxxxxxxx
121const someFunc = () => {
2 return 23
3}
4
5const someOtherFunc = () => {
6 return [1,2,3,4,5,6]
7}
8
9export default {
10 someFunc,
11 someOtherFunc
12}
xxxxxxxxxx
31import defaultExportObject from './defaultExportObject.js'
2
3const someNumber = defaultExportObject.someFunc()